package com.learn.algorithm.designpattern.singleton;

/**
 * 静态内部类实现单例模式
 *
 * 线程安全
 * 只有在调用内部类的时候才会加载内部类,否则不会加载内部类,所以是懒加载
 * @author wangxing
 * @version 2020/5/7 13:52 Administrator
 */
public class LazySingletStaticInnerClass {
    private LazySingletStaticInnerClass() {
    }
    public LazySingletStaticInnerClass getInstance() {
        return Factory.instance;
    }
//    静态内部类实现懒加载
    private static class Factory{
        private static LazySingletStaticInnerClass instance = new LazySingletStaticInnerClass();
    }
}
